import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login.vue')
  },
  {
    path: '/register-info',
    name: 'RegisterInfo',
    component: () => import('@/views/RegisterInfo.vue')
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import('@/views/Home.vue'),
    meta: {
      title: '首页',
      icon: 'House'
    }
  },
  {
    path: '/credit',
    name: 'Credit',
    component: () => import('@/views/credit/Index.vue'),
    meta: {
      title: '信用中心',
      icon: 'CreditCard'
    },
    children: [
      {
        path: 'credit-business',
        name: 'CreditBusiness',
        redirect: '/credit/credit-business/business-shopping/shopping-list',
        meta: {
          title: '信用商业',
          icon: 'Briefcase'
        },
        children: [
          {
            path: 'business-shopping',
            name: 'BusinessShopping',
            redirect: '/credit/credit-business/business-shopping/shopping-list',
            meta: {
              title: '商业购物',
              icon: 'Shop'
            },
            children: [
              {
                path: 'shopping-list',
                name: 'CreditShoppingList',
                component: () => import('@/views/business-shopping/ShoppingList.vue'),
                meta: {
                  title: '信用购物',
                  icon: 'ShoppingCart'
                }
              },
              {
                path: 'product/:id',
                name: 'ProductDetail',
                component: () => import('@/views/business-shopping/ProductDetail.vue'),
                meta: {
                  title: '商品详情',
                  hidden: true
                }
              },
              {
                path: 'cart',
                name: 'ShoppingCart',
                component: () => import('@/views/credit/Cart.vue'),
                meta: {
                  title: '购物车',
                  icon: 'ShoppingCart'
                }
              },
              {
                path: 'orders',
                name: 'ShoppingOrders',
                component: () => import('@/views/credit/ShoppingOrders.vue'),
                meta: {
                  title: '购物订单',
                  icon: 'List'
                }
              }
            ]
          },
          {
            path: 'rental',
            name: 'CreditRentalParent',
            redirect: '/credit/credit-business/rental/list',
            meta: {
              title: '便利租赁',
              icon: 'Box'
            },
            children: [
              {
                path: 'list',
                name: 'CreditRental',
                component: () => import('@/views/credit/RentalList.vue'),
                meta: {
                  title: '租房首页',
                  icon: 'Box'
                }
              },
              {
                path: 'orders',
                name: 'RentalOrders',
                component: () => import('@/views/credit/RentalOrders.vue'),
                meta: {
                  title: '租房订单',
                  icon: 'List'
                }
              }
            ]
          },
          {
            path: 'hotel',
            name: 'CreditHotelParent',
            redirect: '/credit/credit-business/hotel/list',
            meta: {
              title: '酒店预订',
              icon: 'House'
            },
            children: [
              {
                path: 'list',
                name: 'CreditHotel',
                component: () => import('@/views/credit/HotelList.vue'),
                meta: {
                  title: '酒店首页',
                  icon: 'House'
                }
              },
              {
                path: 'orders',
                name: 'HotelOrders',
                component: () => import('@/views/credit/HotelOrders.vue'),
                meta: {
                  title: '酒店订单',
                  icon: 'List'
                }
              }
            ]
          }
        ]
      },
      {
        path: 'life',
        name: 'Life',
        component: () => import('@/views/life/Index.vue'),
        meta: {
          title: '信用生活',
          icon: 'User'
        },
        children: [
          {
            path: 'medical',
            name: 'MedicalAppointment',
            component: () => import('@/views/credit/MedicalAppointment.vue'),
            meta: {
              title: '预约首页',
              icon: 'FirstAidKit'
            }
          },
          {
            path: 'medical-orders',
            name: 'MedicalOrders',
            component: () => import('@/views/credit/MedicalOrders.vue'),
            meta: {
              title: '医疗订单',
              icon: 'List'
            }
          },
          {
            path: 'transport',
            name: 'TransportRideParent',
            redirect: '/credit/life/transport/ride',
            meta: {
              title: '交通出行',
              icon: 'Van'
            },
            children: [
              {
                path: 'ride',
                name: 'TransportRide',
                component: () => import('@/views/credit/TransportRide.vue'),
                meta: {
                  title: '出行首页',
                  icon: 'Van'
                }
              },
              {
                path: 'orders',
                name: 'TransportOrders',
                component: () => import('@/views/credit/TransportOrders.vue'),
                meta: {
                  title: '出行订单',
                  icon: 'List'
                }
              }
            ]
          },
          {
            path: 'parking',
            name: 'ParkingParent',
            redirect: '/credit/life/parking/list',
            meta: {
              title: '停车服务',
              icon: 'Location'
            },
            children: [
              {
                path: 'list',
                name: 'Parking',
                component: () => import('@/views/credit/Parking.vue'),
                meta: {
                  title: '停车首页',
                  icon: 'Location'
                }
              },
              {
                path: 'orders',
                name: 'ParkingOrders',
                component: () => import('@/views/credit/ParkingOrders.vue'),
                meta: {
                  title: '停车订单',
                  icon: 'List'
                }
              }
            ]
          },
          {
            path: 'books',
            name: 'BooksParent',
            redirect: '/credit/life/books/list',
            meta: {
              title: '图书借阅',
              icon: 'Reading'
            },
            children: [
              {
                path: 'list',
                name: 'BookList',
                component: () => import('@/views/life/BookList.vue'),
                meta: {
                  title: '图书借阅首页',
                  icon: 'Reading'
                }
              },
              {
                path: 'records',
                name: 'BookRecords',
                component: () => import('@/views/life/BookRecords.vue'),
                meta: {
                  title: '借阅记录',
                  icon: 'List'
                }
              }
            ]
          }
        ]
      },
      {
        path: 'social',
        name: 'Social',
        component: () => import('@/views/social/Index.vue'),
        redirect: '/credit/social/homepage',
        meta: {
          title: '亲社会行为',
          icon: 'Share'
        },
        children: [
          {
            path: 'homepage',
            name: 'SocialHomepage',
            component: () => import('@/views/social/Index.vue'),
            meta: {
              title: '亲社会行为',
              icon: 'Share'
            }
          },
          {
            path: 'recycle',
            name: 'Recycle',
            component: () => import('@/views/social/Recycle.vue'),
            meta: {
              title: '资源回收',
              icon: 'Delete'
            }
          },
          {
            path: 'water',
            name: 'WaterProtection',
            component: () => import('@/views/social/WaterProtection.vue'),
            meta: {
              title: '护水行动',
              icon: 'Pouring'
            }
          },
          {
            path: 'welfare',
            name: 'Welfare',
            component: () => import('@/views/social/Welfare.vue'),
            meta: {
              title: '公益服务',
              icon: 'Present'
            }
          },
          {
            path: 'activities',
            name: 'Activities',
            component: () => import('@/views/social/ActivityList.vue'),
            meta: {
              title: '活动列表',
              icon: 'Calendar'
            }
          }
        ]
      }
    ]
  },
  {
    path: '/user',
    name: 'User',
    component: () => import('@/views/user/Index.vue'),
    meta: {
      title: '个人中心',
      icon: 'UserFilled'
    },
    redirect: '/user/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'UserProfileDashboard',
        component: () => import('@/views/user/UserProfileDashboard.vue'),
        meta: {
          title: '个人中心仪表盘',
          hidden: true
        }
      },
      {
        path: 'profile',
        name: 'UserProfile',
        component: () => import('@/views/user/Profile.vue'),
        meta: {
          title: '个人信息',
          icon: 'User'
        }
      },
      {
        path: 'records',
        name: 'CreditRecords',
        component: () => import('@/views/credit/CreditRecords.vue'),
        meta: {
          title: '信用记录',
          icon: 'CreditCard'
        }
      },
      {
        path: 'orders',
        name: 'UserOrders',
        component: () => import('@/views/user/Orders.vue'),
        meta: {
          title: '我的订单',
          icon: 'List'
        }
      },
      {
        path: 'activities',
        name: 'UserActivities',
        component: () => import('@/views/user/Activities.vue'),
        meta: {
          title: '我的活动',
          icon: 'Calendar'
        }
      },
      {
        path: 'recharge',
        name: 'UserRecharge',
        component: () => import('@/views/user/Recharge.vue'),
        meta: {
          title: '账户充值',
          icon: 'Money'
        }
      },
      {
        path: 'withdraw',
        name: 'UserWithdraw',
        component: () => import('@/views/user/Withdraw.vue'),
        meta: {
          title: '信用提现',
          icon: 'Wallet'
        }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  document.title = to.meta.title ? `${to.meta.title} - 信用生活平台` : '信用生活平台'
  next()
})

export { routes }
export default router 